var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeName: 1,
    popupShow: false,
    detailList: [],
    page: 1,
    total: 0,
    memberData: [],
    amountSummary: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getTopData();
    this.getAmountLog();
    this.getAmountSummary();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // this.getAmountLog();
    console.log(this.data.page,this.data.total_page)
    this.getMoreData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getMoreData(){
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      this.setData({
        page: this.data.page + 1
      })
      let urlStr = this.data.activeName == 1 ? "plugin.consume-commission.frontend.index.amountLog" : "plugin.consume-commission.frontend.index.rewardLog"
      app._postNetWork({
        url: app.getNetAddresss(urlStr),
        data: {
          page: this.data.page,
        },
        success: (resdata) => {
          let res = resdata.data
          if (res.result == 1) {
            this.data.isLoadMore = true;
            this.setData({
              detailList: this.data.detailList.concat(res.data.data)
            })
          } else {
            this.data.page = this.data.page - 1;
            this.isLoadMore = false
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    }
  },
  toPoint(e) {
    let {
      item
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/packageB/member/love/toIntegral/toIntegral?pool_id=' + item.pool_id + '&name=consumption_dividend_toPoint',
    })
  },
  getAmountSummary() {
    app._getNetWork({
      url: app.getNetAddresss('plugin.consume-commission.frontend.index.amountSummary'),
      data: {},
      success: ({
        data
      }) => {
        if (data.result) {
          this.setData({
            amountSummary: data.data
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: data.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    })
  },
  getTopData() {
    app._getNetWork({
      url: app.getNetAddresss('plugin.consume-commission.frontend.index.index'),
      data: {},
      success: ({
        data
      }) => {
        if (data.result) {
          this.setData({
            memberData: data.data
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: data.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    })
  },
  getAmountLog() {
    let url = this.data.activeName == 1 ? "plugin.consume-commission.frontend.index.amountLog" : "plugin.consume-commission.frontend.index.rewardLog"
    app._getNetWork({
      url: app.getNetAddresss(url),
      data: {
        page: this.data.page,
      },
      success: (respone) => {
        if (respone.data.result !== 1) {
          wx.showToast({
            title: respone.data.msg,
          });
          return false;
        }
        let res = respone.data.data;
        this.data.isLoadMore = true;
        this.data.total_page = res.last_page;
        if (!this.data.total_page) {
          this.data.total_page = 0;
        }
        this.setData({
          detailList: res.data
        })
      }
    });
  },
  clickEvent(event) {
    this.setData({
      activeName: event.detail.name,
      detailList: [],
      page: 1,
      total_page: 0,
    })
    this.getAmountLog();
  },
  onClose() {
    this.setData({
      popupShow: false
    });
  },
  openPopup() {
    this.setData({
      popupShow: true
    });
  },
  // searchScrollLower(ev) {
  //   this.getData();
  // }
})